<?php

namespace app\school\controller;

use library\Controller;
use think\Db;

class Tel extends Controller
{
    public $table = 'sunshineTel';
    public $title = '联系电话管理';
    public function __construct()
    {
        parent::__construct();
        $this->base_route = rtrim(url('',false,false), $this->request->action());
    }
    public function index()
    {
        if($this->request->request('tel')){
            $tel = $this->request->request('tel');
        }else{
            $tel = '';
        }
        return $this->_page(Db::name($this->table)->where('tel','like','%'.$tel.'%'));
    }

    public function add()
    {
        return $this->_form($this->table, 'form');
    }

    public function _add_form_filter(&$data)
    {
        if ($this->request->isPost()) {
            $this->alterInfo($data);
        }
    }

    protected function alterInfo(&$data){
//        if(!is_numeric($data['tel'])){
//            $this->error('联系电话填数字！');
//        }
    }

    public function edit()
    {
        return $this->_form($this->table, 'form');
    }

    public function del()
    {
        return $this->_delete($this->table);
    }

    public function _form_filter(&$data){

    }

    public function upstatus(){
        $this->_save($this->table, [
            'status' => $this->request->request('status'),
        ],'id', ['id' => $this->request->request('id')]);
    }
}
